// pages/integral/integral.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '',
    integral: 0,
    integralList: [],
    pages: 1,
    years: "",
    months: '',
    signFlag:true   //是否签到
  },
  signUp(){
    //签到
    let _this = this;
    wx.request({
      url: getApp().data.servsers + '/user/signIn',
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        userId: getApp().data.userId
      },
      success(res) {
        if (res.data.status == 'success') {
          wx.showModal({
            title: '提示',
            content: '签到成功！',
          })
          _this.setData({
            signFlag:false
          })
        }
      }
    })
  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
    let dates = this.data.date.toString();
    dates= dates.split('-')
    this.setData({
      years: dates[0],
      months: dates[1],
      integralList:[]
    })
    
    this.getIntegralList()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this;
    _this.getIntegralList()
    wx.request({
      url: getApp().data.servsers + '/user/findById.do',
      method: 'POST',
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        id: getApp().data.userId
      },
      success(res) {
        if (res.data.status == 'success') {
          _this.setData({
            signFlag: res.data.flag
          })
          if (res.data.data.amountIntegral) {
            _this.setData({
              integral: res.data.data.amountIntegral
            })
          }
        }
      }
    })
  },
  getIntegralList: function () {
    let _this = this;
    wx.showLoading({
      title: '玩命加载中',
    })
    wx.request({
      url: getApp().data.servsers + '/user/findIntegralDetail',
      method: 'get',
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        id: getApp().data.userId,
        startPage: _this.data.pages,
        PageSize: 10,
        year: _this.data.years,
        month: _this.data.months
      },
      success(res) {
        wx.hideLoading();
        if (res.data.status == 'success') {
          if(_this.data.integralList.length<res.data.data.total){
            _this.setData({
              integralList: _this.data.integralList.concat(res.data.data.list)
            })
          }
          _this.setData({
            pages: _this.data.pages += 1
          })
        }
      }
    })
  },
  onReachBottom: function () {
    this.getIntegralList()
  },
})